apiready = function() {
	api.addEventListener({
		name: 'keyback'
	}, function(ret, err) {
		console.log('按了返回键');
		api.sendEvent({
			name: 'myEvent',
			extra: {
				key1: 'value1',
				key2: 'value2'
			}
		});
	});
	var i;
	var fid = api.pageParam;
	var i = fid.index;
	console.log(i);
	if(i) {
		switch(i) {
			case 1:
				openCommunity();
				break;
			case 2:
				openIndex();
				break;
			case 3:
				openCourse();
				break;
			case 4:
				openUserCenter();
				break;
			default:
				break;
		}
	} else {
		openIndex();
	}

};
//打开商城(主页)
function openIndex() {
	console.log(2);
	openF('index', 'html/mall/mallHome.html', {}, 2, false);
}
//打开课程
function openCourse() {
	console.log(3);
	var uid = $api.getStorage('uid');
	if(uid) {
		openF('course', 'html/course/myClass.html', {}, 3, false);
	} else {
		layout();
	}
}
//打开文章
function openArticle() {
	console.log(0);
	//	closeF('article');
	openF('article', 'html/article/article.html', {}, 0, false);
}
//打开社区
function openCommunity() {
	console.log(1);
	openF('community', 'html/community/community.html', {}, 1, false);
}
//打开个人中心
function openUserCenter() {
	var uid = $api.getStorage('uid');
	if(uid) {
		openF('my', 'html/user/userCenter.html', {}, 4 , false);
	} else {
		layout();
	}
}

function openF(name, url, param, i, reload) {
	api.openFrame({
		name: name,
		url: url,
		animation: {
			type: "push", //动画类型（详见动画类型常量）
			subType: "from_right", //动画子类型（详见动画子类型常量）
			duration: 300 //动画过渡时间，默认300毫秒
		},
		reload: reload,
		rect: {
			x: 0,
			y: 0,
			w: 'auto',
			h: 'auto',
			marginBottom: 48
		},
		vScrollBarEnabled: false,
		pageParam: param
	});
	$(".footer a div").removeClass("active");
	$(".footer a div img.normal").show();
	$(".footer a div img.white").addClass("hide");
	$(".footer a:eq(" + i + ") div").addClass("active");
	$(".footer a:eq(" + i + ") div img.normal").hide();
	$(".footer a:eq(" + i + ") div img.white").removeClass("hide");
}

function layout() {
	api.openWin({
		name: 'login',
		url: 'html/login/login.html',
		vScrollBarEnabled: false,
		reload: true,
	});
}